<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="fmt" 
           uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js">
	</script>
<title>Insert title here</title>
</head>
<body>
	<p style="text-align:center">${sessionScope.name}的订单</p>
	<table width="100%" border=1 style="text-align:center">
		<tr>
			<td>商品名字</td>
			<td>商品类型</td>
			<td>商品价格</td>
			<td>生产日期</td>
			<td>有效期(限食品)</td>
			<td>生产商(限食物和衣服)</td>
			<td>出版社(限书本)</td>
			<td>尺码(限衣服)</td>
			<td>数量</td>
			<td>下架日期</td>
			<td>商品优惠信息</td>
			<td>商品总价</td>
		</tr>
	<c:if test="${enhanceList!=null}">
		<c:forEach items="${enhanceList}" var="enhance">
			<tr>
				<td>${enhance.goods.name}</td>
				<td>${enhance.type.typename}</td>
				<td >${enhance.goods.price}元</td>
				<td><fmt:formatDate value="${enhance.goods.prodate}" pattern="yyyy-MM-dd"/></td>
				<td><fmt:formatDate value="${enhance.goods.effdate}" pattern="yyyy-MM-dd"/></td>
				<td>${enhance.goods.producer}</td>
				<td>${enhance.goods.publisher}</td>
				<td>${enhance.goods.size}</td>
				<td>${enhance.car.goodsnum}</td>
				<td>${enhance.goods.outdate}</td>
				<td>${enhance.discountsMessage.describe}</td>
				<td class="price" >${enhance.goods.price*enhance.car.goodsnum}</td>
			</tr>
		</c:forEach>
	</c:if>
	</table>
	<h2 style="margin-left:1162px">订单总价:<label id="price"></label></h2>
	<button style="float: right" onclick="mySubmit()">确认下单</button>
	<select id="address" name="address" style="float: right">
		<option value="">请选择收货地址</option>
		<c:forEach 	items="${addressList}" var="myaddress">
			<option value="${myaddress.id}">${myaddress.province}${myaddress.city}${myaddress.address}-${myaddress.name}-${myaddress.phonenum}</option>
		</c:forEach>
	</select>
	
	<script>
		$(document).ready(function(){
			var price=0;
			var list=$(".price");
			$.each(list,function(index,content){
				price=parseInt($(content).text())+price;
			});
			$("#price").text(price);
		})
		function mySubmit()
		{
			if($("#address").val()==null||$("#address").val()==""){
				alert("请选择收货地址");
				return;
			}
			var a=confirm("是否确认下单?");
			console.log(a==true);
			if(a){
				window.open("${pageContext.request.contextPath }/user/insertOrder?addressId="+$("#address").val(), "_self");
			}
				
		}
	</script>
</body>
</html>